<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    
    <title>触摸屏校正 | jouyouyun&#39;s blog</title>
    <meta name="viewport" content="width=device-width,minimum-scale=1">
    <meta name="description" content="有些设备的触摸屏不准，需要校正后才能正常使用。校正实际上就是配置设备在 Xorg 中的属性，具体属性名与驱动相关，后文描述。
下面开始介绍校正方法：
准备
安装需要用到的工具：">
    <meta name="generator" content="Hugo 0.105.0">
    
    
    
    
      <meta name="robots" content="noindex, nofollow">
    

    
<link rel="stylesheet" href="/ananke/css/main.min.css" >



    
    
    
      

    

    
    
    <meta property="og:title" content="触摸屏校正" />
<meta property="og:description" content="有些设备的触摸屏不准，需要校正后才能正常使用。校正实际上就是配置设备在 Xorg 中的属性，具体属性名与驱动相关，后文描述。
下面开始介绍校正方法：
准备
安装需要用到的工具：" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://jouyouyun.github.io/post/touchscreen-calibration/" /><meta property="article:section" content="post" />

<meta property="article:modified_time" content="2019-10-25T13:55:59+08:00" />

<meta itemprop="name" content="触摸屏校正">
<meta itemprop="description" content="有些设备的触摸屏不准，需要校正后才能正常使用。校正实际上就是配置设备在 Xorg 中的属性，具体属性名与驱动相关，后文描述。
下面开始介绍校正方法：
准备
安装需要用到的工具：">
<meta itemprop="dateModified" content="2019-10-25T13:55:59+08:00" />
<meta itemprop="wordCount" content="763">
<meta itemprop="keywords" content="touchscreen,calibration,calibrator," /><meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="触摸屏校正"/>
<meta name="twitter:description" content="有些设备的触摸屏不准，需要校正后才能正常使用。校正实际上就是配置设备在 Xorg 中的属性，具体属性名与驱动相关，后文描述。
下面开始介绍校正方法：
准备
安装需要用到的工具："/>

	
  </head>

  <body class="ma0 avenir bg-near-white">

    
   
  

  <header>
    <div class="bg-black">
      <nav class="pv3 ph3 ph4-ns" role="navigation">
  <div class="flex-l justify-between items-center center">
    <a href="/" class="f3 fw2 hover-white no-underline white-90 dib">
      
        jouyouyun&#39;s blog
      
    </a>
    <div class="flex-l items-center">
      

      
        <ul class="pl0 mr3">
          
          <li class="list f5 f4-ns fw4 dib pr3">
            <a class="hover-white no-underline white-90" href="/post/" title="Archives 页">
              Archives
            </a>
          </li>
          
          <li class="list f5 f4-ns fw4 dib pr3">
            <a class="hover-white no-underline white-90" href="/tags/" title="Tags 页">
              Tags
            </a>
          </li>
          
          <li class="list f5 f4-ns fw4 dib pr3">
            <a class="hover-white no-underline white-90" href="/categories/" title="Categories 页">
              Categories
            </a>
          </li>
          
        </ul>
      
      
<div class="ananke-socials">
  
    <a href="https://github.com/jouyouyun" target="_blank" class="github ananke-social-link link-transition stackoverflow link dib z-999 pt3 pt0-l mr1" title="GitHub link" rel="noopener" aria-label="follow on GitHub——Opens in a new window">
      
        <span class="icon"><svg style="enable-background:new 0 0 512 512;" version="1.1" viewBox="0 0 512 512"  xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" >
  <path d="M256,32C132.3,32,32,134.8,32,261.7c0,101.5,64.2,187.5,153.2,217.9c11.2,2.1,15.3-5,15.3-11.1   c0-5.5-0.2-19.9-0.3-39.1c-62.3,13.9-75.5-30.8-75.5-30.8c-10.2-26.5-24.9-33.6-24.9-33.6c-20.3-14.3,1.5-14,1.5-14   c22.5,1.6,34.3,23.7,34.3,23.7c20,35.1,52.4,25,65.2,19.1c2-14.8,7.8-25,14.2-30.7c-49.7-5.8-102-25.5-102-113.5   c0-25.1,8.7-45.6,23-61.6c-2.3-5.8-10-29.2,2.2-60.8c0,0,18.8-6.2,61.6,23.5c17.9-5.1,37-7.6,56.1-7.7c19,0.1,38.2,2.6,56.1,7.7   c42.8-29.7,61.5-23.5,61.5-23.5c12.2,31.6,4.5,55,2.2,60.8c14.3,16.1,23,36.6,23,61.6c0,88.2-52.4,107.6-102.3,113.3   c8,7.1,15.2,21.1,15.2,42.5c0,30.7-0.3,55.5-0.3,63c0,6.1,4,13.3,15.4,11C415.9,449.1,480,363.1,480,261.7   C480,134.8,379.7,32,256,32z"/>
</svg>
</span>
      
<span class="new-window"><svg  height="8px"  style="enable-background:new 0 0 1000 1000;" version="1.1" viewBox="0 0 1000 1000"  xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" >
<path d="M598 128h298v298h-86v-152l-418 418-60-60 418-418h-152v-86zM810 810v-298h86v298c0 46-40 86-86 86h-596c-48 0-86-40-86-86v-596c0-46 38-86 86-86h298v86h-298v596h596z" style="fill-rule:evenodd;clip-rule:evenodd;"/>
</svg>
</span></a>
  
</div>

    </div>
  </div>
</nav>

    </div>
  </header>



    <main class="pb7" role="main">
      
  
  <article class="flex-l flex-wrap justify-between mw8 center ph3">
    <header class="mt4 w-100">
      <aside class="instapaper_ignoref b helvetica tracked">
          
        POSTS
      </aside>
      










  <div id="sharing" class="mt3 ananke-socials">
    
  </div>


      <h1 class="f1 athelas mt3 mb1">触摸屏校正</h1>
      
      <p class="tracked">
         <strong>jouyouyun</strong>
      </p>
      
      
      
      <time class="f6 mv4 dib tracked" datetime="2019-10-25T13:55:59+08:00">十月 25, 2019</time>
      

      
      
    </header>
    <div class="nested-copy-line-height lh-copy serif f4 nested-links mid-gray pr4-l w-two-thirds-l"><p>有些设备的触摸屏不准，需要校正后才能正常使用。校正实际上就是配置设备在 <code>Xorg</code> 中的属性，具体属性名与驱动相关，后文描述。</p>
<p>下面开始介绍校正方法：</p>
<h2 id="准备">准备</h2>
<p>安装需要用到的工具：</p>
<ul>
<li>xinput-calibrator : 触摸屏校正工具</li>
<li>xinput : 屏幕映射工具，多屏时使用</li>
</ul>
<hr>
<h2 id="校正">校正</h2>
<ol>
<li>
<p>执行 <code>xinput_calibrator --list</code> 查看触摸设备列表</p>
</li>
<li>
<p>校正设备 <code>xinput_calibrator -v --device &lt;device name or id&gt;</code></p>
<p><code>device name or id</code> 从上面的  <code>list</code> 中得到</p>
</li>
</ol>
<p>此时会出现校正界面，按照提示点击，成功后程序会输出校正后的数据。</p>
<p>接着根据驱动的不同选择不同的设置方法，查看设备使用的驱动可通过 <code>/var/log/Xorg.0.log</code> 文件得到。</p>
<ul>
<li>
<p>evdev</p>
<p>使用 <code>evedev</code> 驱动时可直接使用 <code>xinput_calibrator</code> 输出的数据，无需其它设置。</p>
<p>测试时使用 <code>xinput</code> 设置 <code>Evdev Axis Calibration</code> 属性。</p>
</li>
<li>
<p>libinput</p>
<p>使用 <code>libinput</code> 驱动时需要将 <code>xinput_calibrator</code> 输出的数据进行计算才可使用，计算方法参见： <a href="https://wiki.archlinux.org/index.php/Talk:Calibrating%5FTouchscreen#Libinput%5Fbreaks%5Fxinput%5Fcalibrator">Libinput breaks xinput_calibrator</a></p>
<p>在此将计算方法写成了一个脚本，内容如下：</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-python" data-lang="python"><span style="display:flex;"><span><span style="color:#75715e">#!/usr/bin/env python3</span>
</span></span><span style="display:flex;"><span><span style="color:#75715e"># -*- coding: UTF-8 -*-</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">import</span> sys
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">usage</span>():
</span></span><span style="display:flex;"><span>    info <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;Usage: &#34;</span> <span style="color:#f92672">+</span> sys<span style="color:#f92672">.</span>argv[<span style="color:#ae81ff">0</span>]
</span></span><span style="display:flex;"><span>    info <span style="color:#f92672">+=</span> <span style="color:#e6db74">&#34; &lt;screen_width&gt; &lt;screen_height&gt;&#34;</span>
</span></span><span style="display:flex;"><span>    info <span style="color:#f92672">+=</span> <span style="color:#e6db74">&#34; &lt;click_0_x&gt; &lt;click_0_y&gt;&#34;</span>
</span></span><span style="display:flex;"><span>    info <span style="color:#f92672">+=</span> <span style="color:#e6db74">&#34; &lt;click_3_x&gt; &lt;click_3_y&gt;&#34;</span>
</span></span><span style="display:flex;"><span>    print(info)
</span></span><span style="display:flex;"><span>    print(<span style="color:#e6db74">&#34;</span><span style="color:#ae81ff">\t</span><span style="color:#e6db74">Screen width/hight by the command &#39;xrandr|grep screen&#39; got&#34;</span>)
</span></span><span style="display:flex;"><span>    print(<span style="color:#e6db74">&#34;</span><span style="color:#ae81ff">\t</span><span style="color:#e6db74">Click x/y by the command &#39;xinput_calibrator -v&#39; got&#34;</span>)
</span></span><span style="display:flex;"><span>    sys<span style="color:#f92672">.</span>exit(<span style="color:#ae81ff">0</span>)
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">def</span> <span style="color:#a6e22e">convert</span>(screen_x, screen_y, c0_x, c0_y, c3_x, c3_y):
</span></span><span style="display:flex;"><span>    a <span style="color:#f92672">=</span> (screen_x <span style="color:#f92672">*</span> <span style="color:#ae81ff">6</span> <span style="color:#f92672">/</span> <span style="color:#ae81ff">8</span>) <span style="color:#f92672">/</span> (c3_x <span style="color:#f92672">-</span> c0_x)
</span></span><span style="display:flex;"><span>    c <span style="color:#f92672">=</span> ((screen_x <span style="color:#f92672">/</span> <span style="color:#ae81ff">8</span>) <span style="color:#f92672">-</span> (a <span style="color:#f92672">*</span> c0_x)) <span style="color:#f92672">/</span> screen_x
</span></span><span style="display:flex;"><span>    e <span style="color:#f92672">=</span> (screen_y <span style="color:#f92672">*</span> <span style="color:#ae81ff">6</span> <span style="color:#f92672">/</span> <span style="color:#ae81ff">8</span>) <span style="color:#f92672">/</span> (c3_y <span style="color:#f92672">-</span> c0_y)
</span></span><span style="display:flex;"><span>    f <span style="color:#f92672">=</span> ((screen_y <span style="color:#f92672">/</span> <span style="color:#ae81ff">8</span>) <span style="color:#f92672">-</span> (e <span style="color:#f92672">*</span> c0_y)) <span style="color:#f92672">/</span> screen_y
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    print(<span style="color:#e6db74">&#34;Try set &#39;libinput Calibration Matrix&#39; to &#39;</span><span style="color:#e6db74">%.1f</span><span style="color:#e6db74">, 0.0, </span><span style="color:#e6db74">%.1f</span><span style="color:#e6db74">, 0.0, </span><span style="color:#e6db74">%.1f</span><span style="color:#e6db74">, </span><span style="color:#e6db74">%.1f</span><span style="color:#e6db74">, 0.0, 0.0, 1.0&#39;&#34;</span> <span style="color:#f92672">%</span> (a,c,e, f))
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">if</span> __name__ <span style="color:#f92672">==</span> <span style="color:#e6db74">&#34;__main__&#34;</span>:
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">if</span> len(sys<span style="color:#f92672">.</span>argv) <span style="color:#f92672">!=</span> <span style="color:#ae81ff">7</span>:
</span></span><span style="display:flex;"><span>        usage()
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>    convert(int(sys<span style="color:#f92672">.</span>argv[<span style="color:#ae81ff">1</span>]), int(sys<span style="color:#f92672">.</span>argv[<span style="color:#ae81ff">2</span>]), int(sys<span style="color:#f92672">.</span>argv[<span style="color:#ae81ff">3</span>]),
</span></span><span style="display:flex;"><span>    int(sys<span style="color:#f92672">.</span>argv[<span style="color:#ae81ff">4</span>]),int(sys<span style="color:#f92672">.</span>argv[<span style="color:#ae81ff">5</span>]),int(sys<span style="color:#f92672">.</span>argv[<span style="color:#ae81ff">6</span>]))
</span></span></code></pre></div><p>测试时使用 <code>xinput</code> 设置 <code>libinput Calibration Matrix</code> 属性。</p>
<p>若上面计算的值设置后仍有问题，尝试 <a href="https://wiki.archlinux.org/index.php/Calibrating%5FTouchscreen#Calculate%5Fthe%5FCoordinate%5FTransformation%5FMatrix">Calculate the Coordinate Transformation Matrix</a> 这种计算方法。</p>
<p>如若都不行切换到 <code>evdev</code> 驱动，即安装 <code>xserver-xorg-input-evdev</code> 然后添加 <code>99-touchscreen-evdev.conf</code> 到 <code>/etc/X11/xorg.conf.d</code> 目录, 内容如下：</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span>Section <span style="color:#e6db74">&#34;InputClass&#34;</span>
</span></span><span style="display:flex;"><span>      Identifier	<span style="color:#e6db74">&#34;calibration&#34;</span>
</span></span><span style="display:flex;"><span>      Driver	<span style="color:#e6db74">&#34;evdev&#34;</span>
</span></span><span style="display:flex;"><span>      MatchProduct	<span style="color:#e6db74">&#34;&lt;touchscreen product&gt;&#34;</span>
</span></span><span style="display:flex;"><span>EndSection
</span></span></code></pre></div><p>其中的 <code>touchscreen product</code> 可以从 <code>/var/log/Xorg.0.log</code> 得到。</p>
</li>
</ul>
<hr>
<h3 id="示例">示例</h3>
<p>如在 <code>Huawei</code> 上执行校正操作的输出如下：</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span>deepin@deepin-PC:~$ xinput_calibrator -v
</span></span><span style="display:flex;"><span>DEBUG: XInputExtension version is 2.3
</span></span><span style="display:flex;"><span>DEBUG: Skipping virtual master devices and devices without axis valuators.
</span></span><span style="display:flex;"><span>DEBUG: Skipping device <span style="color:#e6db74">&#39;Virtual core XTEST pointer&#39;</span> id<span style="color:#f92672">=</span>4, does not report Absolute events.
</span></span><span style="display:flex;"><span>DEBUG: Skipping device <span style="color:#e6db74">&#39;SYNA1D31:00 06CB:CD48 Touchpad&#39;</span> id<span style="color:#f92672">=</span>12, does not report Absolute events.
</span></span><span style="display:flex;"><span>DEBUG: Selected device: SYNA2393:00 06CB:19AC
</span></span><span style="display:flex;"><span>DEBUG: Not usbtouchscreen calibrator: Not a usbtouchscreen device
</span></span><span style="display:flex;"><span>DEBUG: Evdev Axis Calibration not set, setting to axis valuators to be sure.
</span></span><span style="display:flex;"><span>        Setting calibration data: 0, 3000, 0, <span style="color:#ae81ff">2000</span>
</span></span><span style="display:flex;"><span>DEBUG: Successfully applied axis calibration.
</span></span><span style="display:flex;"><span>DEBUG: Read axes swap value of 0.
</span></span><span style="display:flex;"><span>DEBUG: Read InvertX<span style="color:#f92672">=</span>0, InvertY<span style="color:#f92672">=</span>0.
</span></span><span style="display:flex;"><span>Calibrating EVDEV driver <span style="color:#66d9ef">for</span> <span style="color:#e6db74">&#34;SYNA2393:00 06CB:19AC&#34;</span> id<span style="color:#f92672">=</span><span style="color:#ae81ff">11</span>
</span></span><span style="display:flex;"><span>        current calibration values <span style="color:#f92672">(</span>from XInput<span style="color:#f92672">)</span>: min_x<span style="color:#f92672">=</span>0, max_x<span style="color:#f92672">=</span><span style="color:#ae81ff">3000</span> and min_y<span style="color:#f92672">=</span>0, max_y<span style="color:#f92672">=</span><span style="color:#ae81ff">2000</span>
</span></span><span style="display:flex;"><span>DEBUG: Found that <span style="color:#e6db74">&#39;SYNA2393:00 06CB:19AC&#39;</span> is a sysfs name.
</span></span><span style="display:flex;"><span>DEBUG: Adding click <span style="color:#ae81ff">0</span> <span style="color:#f92672">(</span>X<span style="color:#f92672">=</span>382, Y<span style="color:#f92672">=</span>246<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>DEBUG: Adding click <span style="color:#ae81ff">1</span> <span style="color:#f92672">(</span>X<span style="color:#f92672">=</span>2647, Y<span style="color:#f92672">=</span>246<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>DEBUG: Adding click <span style="color:#ae81ff">2</span> <span style="color:#f92672">(</span>X<span style="color:#f92672">=</span>376, Y<span style="color:#f92672">=</span>1761<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>DEBUG: Adding click <span style="color:#ae81ff">3</span> <span style="color:#f92672">(</span>X<span style="color:#f92672">=</span>2640, Y<span style="color:#f92672">=</span>1764<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>Doing dynamic recalibration:
</span></span><span style="display:flex;"><span>        Setting calibration data: 2, 3021, -7, <span style="color:#ae81ff">2015</span>
</span></span><span style="display:flex;"><span>DEBUG: Successfully applied axis calibration.
</span></span><span style="display:flex;"><span>        --&gt; Making the calibration permanent &lt;--
</span></span><span style="display:flex;"><span>DEBUG: Found that <span style="color:#e6db74">&#39;SYNA2393:00 06CB:19AC&#39;</span> is a sysfs name.
</span></span><span style="display:flex;"><span>  copy the snippet below into <span style="color:#e6db74">&#39;/etc/X11/xorg.conf.d/99-calibration.conf&#39;</span> <span style="color:#f92672">(</span>/usr/share/X11/xorg.conf.d/ in some distro<span style="color:#960050;background-color:#1e0010">&#39;</span>s<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span>Section <span style="color:#e6db74">&#34;InputClass&#34;</span>
</span></span><span style="display:flex;"><span>        Identifier	<span style="color:#e6db74">&#34;calibration&#34;</span>
</span></span><span style="display:flex;"><span>        MatchProduct	<span style="color:#e6db74">&#34;SYNA2393:00 06CB:19AC&#34;</span>
</span></span><span style="display:flex;"><span>        Option	<span style="color:#e6db74">&#34;Calibration&#34;</span>	<span style="color:#e6db74">&#34;2 3021 -7 2015&#34;</span>
</span></span><span style="display:flex;"><span>        Option	<span style="color:#e6db74">&#34;SwapAxes&#34;</span>	<span style="color:#e6db74">&#34;0&#34;</span>
</span></span><span style="display:flex;"><span>EndSection
</span></span></code></pre></div><p><code>Xorg.0.log</code> 中设备驱动相关的日志如下：</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span><span style="color:#f92672">[</span>  7221.421<span style="color:#f92672">]</span> <span style="color:#f92672">(</span>II<span style="color:#f92672">)</span> config/udev: Adding input device SYNA2393:00 06CB:19AC <span style="color:#f92672">(</span>/dev/input/event7<span style="color:#f92672">)</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>  7221.421<span style="color:#f92672">]</span> <span style="color:#f92672">(</span>**<span style="color:#f92672">)</span> SYNA2393:00 06CB:19AC: Applying InputClass <span style="color:#e6db74">&#34;evdev touchscreen catchall&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>  7221.421<span style="color:#f92672">]</span> <span style="color:#f92672">(</span>**<span style="color:#f92672">)</span> SYNA2393:00 06CB:19AC: Applying InputClass <span style="color:#e6db74">&#34;libinput touchscreen catchall&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>  7221.421<span style="color:#f92672">]</span> <span style="color:#f92672">(</span>**<span style="color:#f92672">)</span> SYNA2393:00 06CB:19AC: Applying InputClass <span style="color:#e6db74">&#34;calibration&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>  7221.421<span style="color:#f92672">]</span> <span style="color:#f92672">(</span>II<span style="color:#f92672">)</span> LoadModule: <span style="color:#e6db74">&#34;evdev&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>  7221.421<span style="color:#f92672">]</span> <span style="color:#f92672">(</span>II<span style="color:#f92672">)</span> Loading /usr/lib/xorg/modules/input/evdev_drv.so
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>  7221.421<span style="color:#f92672">]</span> <span style="color:#f92672">(</span>II<span style="color:#f92672">)</span> Module evdev: vendor<span style="color:#f92672">=</span><span style="color:#e6db74">&#34;X.Org Foundation&#34;</span>
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>  7221.421<span style="color:#f92672">]</span>    compiled <span style="color:#66d9ef">for</span> 1.19.1, module version <span style="color:#f92672">=</span> 2.10.5
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>  7221.421<span style="color:#f92672">]</span>    Module class: X.Org XInput Driver
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>  7221.421<span style="color:#f92672">]</span>    ABI class: X.Org XInput driver, version 24.1
</span></span><span style="display:flex;"><span><span style="color:#f92672">[</span>  7221.421<span style="color:#f92672">]</span> <span style="color:#f92672">(</span>II<span style="color:#f92672">)</span> Using input driver <span style="color:#e6db74">&#39;evdev&#39;</span> <span style="color:#66d9ef">for</span> <span style="color:#e6db74">&#39;SYNA2393:00 06CB:19AC&#39;</span>
</span></span></code></pre></div><hr>
<ul>
<li>evdev</li>
</ul>
<p>执行命令 <code>xinput set-prop 11 Evdev Axis Calibration 2 3021 -7 2015</code> 测试效果</p>
<hr>
<ul>
<li>libinput</li>
</ul>
<p>使用上面的 <code>click 0</code> 和 <code>click 3</code> 的值以及 <code>xrandr</code> 得到的 <code>screen width/height</code> 计算，得到的值如下：</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span>$ python3 ./touchscreen_calibration_convert.py <span style="color:#ae81ff">344</span> <span style="color:#ae81ff">193</span> <span style="color:#ae81ff">382</span> <span style="color:#ae81ff">246</span> <span style="color:#ae81ff">376</span> <span style="color:#ae81ff">1761</span>
</span></span><span style="display:flex;"><span>Try set <span style="color:#e6db74">&#39;libinput Calibration Matrix&#39;</span> to <span style="color:#e6db74">&#39;-43.0, 0.0, 47.9, 0.0, 0.1, 0.0, 0.0, 0.0, 1.0&#39;</span>
</span></span></code></pre></div><p>执行命令 <code>xinput set-prop 11 libinput Calibration Matrix -43.0 0.0 47.9 0.0 0.1 0.0 0.0 0.0 1.0</code> 测试效果。</p>
<h3 id="额外问题">额外问题</h3>
<p>某些设备按照上述步骤设置后仍然有一些问题，这里列出一些遇到过的，一旦出现下面这些情况，请先切换驱动到 <code>evdev</code> 然后进行设置。</p>
<h4 id="上下相反">上下相反</h4>
<p>如点击 <strong><strong>左上角</strong></strong> 却反馈在 <strong><strong>左下角</strong></strong> ，在 <code>90-touchscreen-calibrator.conf</code> 中加上 <code>Option InvertY &quot;true&quot;</code> 。</p>
<h4 id="左右相反">左右相反</h4>
<p>如点击 <strong><strong>左上角</strong></strong> 却反馈在 <strong><strong>右下角</strong></strong> ，在 <code>90-touchscreen-calibrator.conf</code> 中加上 <code>Option InvertX &quot;true&quot;</code> 。</p>
<h4 id="边缘偏移">边缘偏移</h4>
<p>如点击最右边却反馈在旁边的区域，此时可调整 <code>Option Calibration</code> 的值，其值的含有为： <code>&quot;min-x max-x min-y max-y&quot;</code> 。在四个边缘都试下，然后调整对应的值。</p>
<h4 id="xy-相反"><code>XY</code> 相反</h4>
<p>如点击 <strong><strong>左上角</strong></strong> 却反馈在 <strong><strong>右上角</strong></strong> ，在 <code>90-touchscreen-calibrator.conf</code> 中加上 <code>Option SwapAxes &quot;true&quot;</code> 。</p>
<h2 id="持久化">持久化</h2>
<p>上面的测试无误后，就开始集成到系统中，每次启动时都自动执行。</p>
<p>自动执行通过 <code>xorg.conf.d</code> 钩子执行，添加 <code>90-touchscreen-calibrator.conf</code> 到 <code>/etc/X11/xorg.conf.d/</code> 目录中。</p>
<h3 id="evdev">evdev</h3>
<p>示例内容如下：</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span>Section <span style="color:#e6db74">&#34;InputClass&#34;</span>
</span></span><span style="display:flex;"><span>        Identifier	<span style="color:#e6db74">&#34;calibration&#34;</span>
</span></span><span style="display:flex;"><span>        MatchProduct	<span style="color:#e6db74">&#34;SYNA2393:00 06CB:19AC&#34;</span>
</span></span><span style="display:flex;"><span>        Option	<span style="color:#e6db74">&#34;Calibration&#34;</span>	<span style="color:#e6db74">&#34;2 3021 -7 2015&#34;</span>
</span></span><span style="display:flex;"><span>        Option	<span style="color:#e6db74">&#34;SwapAxes&#34;</span>	<span style="color:#e6db74">&#34;0&#34;</span>
</span></span><span style="display:flex;"><span>EndSection
</span></span></code></pre></div><h3 id="libinput">libinput</h3>
<p>示例内容如下：</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span>Section <span style="color:#e6db74">&#34;InputClass&#34;</span>
</span></span><span style="display:flex;"><span>        Identifier	<span style="color:#e6db74">&#34;calibration&#34;</span>
</span></span><span style="display:flex;"><span>        MatchProduct	<span style="color:#e6db74">&#34;SYNA2393:00 06CB:19AC&#34;</span>
</span></span><span style="display:flex;"><span>        Option	<span style="color:#e6db74">&#34;CalibrationMatrix&#34;</span>	<span style="color:#e6db74">&#34;-43.0 0.0 47.9 0.0 0.1 0.0 0.0 0.0 1.0&#34;</span>
</span></span><span style="display:flex;"><span>EndSection
</span></span></code></pre></div><h2 id="设备映射">设备映射</h2>
<p>若存在多块屏幕，这时就需要指定触摸屏对应的设备，使用 <code>xinput --map-output-to &lt;device id&gt; &lt;output name&gt;</code> 。</p>
<p><code>device name</code> 就是上文中得到的 <code>id</code> ， <code>output name</code> 可通过  <code>xrandr</code> 命令得到。</p>
<h3 id="持久化">持久化</h3>
<p>可添加 <code>90-touchscreen-map</code> 到 <code>/etc/X11/xinit/xinitrc.d</code> 目录，内容就是上面的命令。</p>
<h2 id="登录界面校正">登录界面校正</h2>
<p>目前 <code>deepin</code> 使用 <code>lightdm</code> 做为登录管理器，所以需要修改 <code>lightdm</code> 的配置文件来设置校正数据。</p>
<p>修改 <code>/etc/lightdm/lightdm.conf</code> 文件中 <code>[Seat:*]</code> 组的 <code>display-setup-script</code> 字段，值为指定的校正脚本路径(需要先取消注释)。</p>
<p>脚本文件里只能使用命令，上面的校正过程中用到的正确的 <code>xinput</code> 命令要写入这个文件，包括设备映射的命令。</p>
<p>如在华为上就只需映射设备，所以添加文件 <code>/etc/lightdm/display_setup.sh</code> ，内容如下：</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span><span style="color:#75715e">#!/bin/bash
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span>
</span></span><span style="display:flex;"><span>xinput --map-output-to <span style="color:#e6db74">&#34;SYNA2393:00 06CB:19AC&#34;</span> eDP-1
</span></span></code></pre></div><p>而 <code>/etc/lightdm/lightdm.conf</code> 则修改为(只给出修改的部分)：</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-shell" data-lang="shell"><span style="display:flex;"><span><span style="color:#f92672">[</span>Seat:*<span style="color:#f92672">]</span>
</span></span><span style="display:flex;"><span>display-setup-script<span style="color:#f92672">=</span>/etc/lightdm/display_setup.sh
</span></span></code></pre></div><h2 id="参考文档">参考文档</h2>
<ul>
<li><code>man 4 evdev</code> : 需要安装 <code>xserver-xorg-input-evdev</code></li>
<li><code>man 4 libinput</code> : 需要安装 <code>xserver-xorg-input-libinput</code></li>
</ul><ul class="pa0">
  
   <li class="list di">
     <a href="/tags/touchscreen" class="link f5 grow no-underline br-pill ba ph3 pv2 mb2 dib black sans-serif">touchscreen</a>
   </li>
  
   <li class="list di">
     <a href="/tags/calibration" class="link f5 grow no-underline br-pill ba ph3 pv2 mb2 dib black sans-serif">calibration</a>
   </li>
  
   <li class="list di">
     <a href="/tags/calibrator" class="link f5 grow no-underline br-pill ba ph3 pv2 mb2 dib black sans-serif">calibrator</a>
   </li>
  
</ul>
<div class="mt6 instapaper_ignoref">
      
      
      </div>
    </div>

    <aside class="w-30-l mt6-l">




</aside>

  </article>

    </main>
    <footer class="bg-black bottom-0 w-100 pa3" role="contentinfo">
  <div class="flex justify-between">
  <a class="f4 fw4 hover-white no-underline white-70 dn dib-ns pv2 ph3" href="https://jouyouyun.github.io" >
    &copy;  jouyouyun 2023 
  </a>
    <div>
<div class="ananke-socials">
  
    <a href="https://github.com/jouyouyun" target="_blank" class="github ananke-social-link link-transition stackoverflow link dib z-999 pt3 pt0-l mr1" title="GitHub link" rel="noopener" aria-label="follow on GitHub——Opens in a new window">
      
        <span class="icon"><svg style="enable-background:new 0 0 512 512;" version="1.1" viewBox="0 0 512 512"  xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" >
  <path d="M256,32C132.3,32,32,134.8,32,261.7c0,101.5,64.2,187.5,153.2,217.9c11.2,2.1,15.3-5,15.3-11.1   c0-5.5-0.2-19.9-0.3-39.1c-62.3,13.9-75.5-30.8-75.5-30.8c-10.2-26.5-24.9-33.6-24.9-33.6c-20.3-14.3,1.5-14,1.5-14   c22.5,1.6,34.3,23.7,34.3,23.7c20,35.1,52.4,25,65.2,19.1c2-14.8,7.8-25,14.2-30.7c-49.7-5.8-102-25.5-102-113.5   c0-25.1,8.7-45.6,23-61.6c-2.3-5.8-10-29.2,2.2-60.8c0,0,18.8-6.2,61.6,23.5c17.9-5.1,37-7.6,56.1-7.7c19,0.1,38.2,2.6,56.1,7.7   c42.8-29.7,61.5-23.5,61.5-23.5c12.2,31.6,4.5,55,2.2,60.8c14.3,16.1,23,36.6,23,61.6c0,88.2-52.4,107.6-102.3,113.3   c8,7.1,15.2,21.1,15.2,42.5c0,30.7-0.3,55.5-0.3,63c0,6.1,4,13.3,15.4,11C415.9,449.1,480,363.1,480,261.7   C480,134.8,379.7,32,256,32z"/>
</svg>
</span>
      
<span class="new-window"><svg  height="8px"  style="enable-background:new 0 0 1000 1000;" version="1.1" viewBox="0 0 1000 1000"  xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" >
<path d="M598 128h298v298h-86v-152l-418 418-60-60 418-418h-152v-86zM810 810v-298h86v298c0 46-40 86-86 86h-596c-48 0-86-40-86-86v-596c0-46 38-86 86-86h298v86h-298v596h596z" style="fill-rule:evenodd;clip-rule:evenodd;"/>
</svg>
</span></a>
  
</div>
</div>
  </div>
</footer>

  </body>
</html>
